package com.ecommerce.dal.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ecommerce.dal.dao.IUserCommunicationDAO;
import com.ecommerce.dal.entity.UserCommunication;
import com.ecommerce.dal.util.CustomHibernateDAOSupport;

@Repository("userCommunicationDAO")
public class UserCommunicationDAO extends CustomHibernateDAOSupport implements
		IUserCommunicationDAO {

	@Override
	public void save(UserCommunication userCommunication) {
		getHibernateTemplate().save(userCommunication);

	}

	@Override
	public void update(UserCommunication userCommunication) {
		getHibernateTemplate().update(userCommunication);
	}

	@Override
	public void delete(UserCommunication userCommunication) {
		getHibernateTemplate().delete(userCommunication);

	}

	@Override
	public List<UserCommunication> findByUserId(long userId) {
		List list = getHibernateTemplate()
				.find("select userCommunication from UserCommunication userCommunication inner join userCommunication.user user where user.userId=?",
						userId);
		return ((list != null && list.size()>0) ?  list : null) ;
	}

	@Override
	public List<UserCommunication> findByUserName(String userName) {
		List list = getHibernateTemplate()
				.find("select userCommunication from UserCommunication userCommunication inner join userCommunication.user user where user.userName=?",
						userName);
		return ((list != null && list.size()>0) ?  list : null) ;
	}

}
